//
//  WYWTabBar.swift
//  WYWImitateMicroBlog
//
//  Created by 王永旺永旺 on 2016/10/22.
//  Copyright © 2016年 wangwang. All rights reserved.
//

import UIKit


/// 这个类是为了添加中间的那个大的撰写的按钮而写的自定义
class WYWTabBar: UITabBar {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }
    
     //MARK: - 当使用xib或者是 sb 的时候就会调用这个方法
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
        //设置按钮的frame
        composeButton.center.x = frame.size.width * 0.5
        composeButton.center.y = frame.size.height * 0.5
        
        let w = WYWSCREENW * 0.2
        var index: CGFloat = 0
        for value in subviews{
//            if value is kind(of:NSClassFromString("UITabBarButton")){
//                value.frame.width = w
//                value.frame.origin.x = index * w
//
//            }
            if value.isKind(of: NSClassFromString("UITabBarButton")!){
                value.frame.size.width = w
                value.frame.origin.x = index * w
                
                index += 1
                if index == 2 {
                    index += 1
                }
                
            }
            
        }
    }
     //MARK: - 设置视图
    private func setupUI(){
        addSubview(composeButton)
    
    }
    
     //MARK: - 懒加载控件
    private lazy var composeButton: UIButton = {
        
        let button = UIButton()
//        button.setImage(UIImage(named:"tabbar_compose_icon")), for: UIControlState.normal)
        button.setImage(UIImage.init(named: "tabbar_compose_icon_add"), for: UIControlState.normal)
        button.setImage(UIImage.init(named: "tabbar_compose_icon_add_highLighted"), for: UIControlState.highlighted)
        button.setBackgroundImage(UIImage.init(named: "tabbar_compose_button"), for: UIControlState.normal)
         button.setBackgroundImage(UIImage.init(named: "tabbar_compose_button_highLighted"), for: UIControlState.highlighted)
        button.sizeToFit()
        
        
        
        return button
        
        
    }()

}
